// app.ts
App<IAppOption>({
  globalData: {
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
    navHeight: 0,
    loginShowing: false,
    channel: ''
  },
  onLaunch() {
    const response = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        console.log(res)
        const scale = 750 / res.windowWidth;
        this.globalData.statusBarHeight = res.statusBarHeight * scale
        this.globalData.navHeight = ((response.top - res.statusBarHeight) * 2 + response.height) * scale
        console.log(this.globalData);
      }
    })
  },
  toPhoneLoginPage(): void {
    console.log('to phone login page');
    let pages = getCurrentPages();
    let page = pages[pages.length - 1];
    let loginpop = page.selectComponent('#loginpop');
    if (!loginpop) {
      return;
    }
    let pageUnload = page.onUnload();
    page.onUnload = () => {
      getApp().globalData.loginShowing = false;
      if (pageUnload) {
        //@ts-ignore
        pageUnload();
      }
      //@ts-ignore
      page.onUnload = pageUnload;
    }
    loginpop.show(() => {
      if (page.onLoad) {
        page.onLoad();
      }
      if (page.onShow) {
        page.onShow();
      }
    }, () => {
      if (pages.length === 1) {
        wx.switchTab({
          url: '/pages/index/index'
        })
      } else {
        wx.navigateBack();
      }
    });
  }
})